#include<bits/stdc++.h>
#define ll long long
#define int ll
#define L x<<1
#define R L|1
#define mid (l+r>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define OK Ll<=l&&r<=Rr
#define Root 1,1,n
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N =1e6+5,M=1e6+5,inf=(1LL<<31)-1,mod=998244853;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,int b){if(!b)return 1;int c=qp(a,b>>1);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
int n,sa[N],len[N],f[N],c[N],a[N];
inline int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
bool fl;
inline bool cmp(int l,int r){
	while(l<=n&&r<=n&&a[l]==a[r])l++,r++;
	if(l>n||r>n)return l>r;
	return a[l]<a[r];
}
inline void baoli(int pos){
	if(fl)return;
	if(pos==n+1){
		rep(i,1,n-1){
			int l=sa[i],r=sa[i+1];
			while(l<=n&&r<=n&&a[l]==a[r])l++,r++;
			if(l>n||r>n){
				if(r>n)return;
			}else {
				if(a[l]>a[r])return;
			}
		}
		repn(i){
			int w=len[i*2-1]/2;
			rep(j,1,w)if(a[i-j]!=a[i+j])return;
			if(i-w-1>=1&&i+w+1<=n){
				if(a[i-w-1]==a[i+w+1])return;
			}
		}
		rep(i,1,n-1){
			int w=len[i*2]/2;
			rep(j,1,w)if(a[i-j+1]!=a[i+j])return;
			if(i-w>=1&&i+w+1<=n){
				if(a[i-w]==a[i+w+1])return;
			}
		}
		fl=1;
		repn(i)putchar('a'+a[i]-1);
		putchar('\n');
		return;
	}
	repn(i)a[pos]=i,baoli(pos+1);
}
inline void subtask0(){
	fl=0;
	baoli(1);
	if(!fl)puts("-1");
}
vector<int>p[N];
inline void subA(){
	a[n]=1;
	repn(i)p[i].clear();
	repn(i){
		int w=len[i*2-1]/2;
		if(i-w-1<1||i+w+1>n)continue;
		p[i-w-1].pb(i+w+1);
	}
	rep(i,1,n-1){
		int w=len[i*2]/2;
		if(i-w<1||i+w+1>n)continue;
		p[i-w].pb(i+w+1);
	}
	a[n]=1;
	per(i,n-1,1){
		a[i]=a[i+1];
		E(i)if(a[y]==a[i])a[i]++;
		if(a[i]>26)return puts("-1"),void();
	}
	repn(i){
		int w=len[i*2-1]/2;
		if(a[i-w]!=a[i+w])return puts("-1"),void();
	}
	rep(i,1,n-1){
		int w=len[i*2]/2;
		if(!w)continue;
		if(a[i-w+1]!=a[i+w])return puts("-1"),void();
	}
	repn(i)putchar('a'+a[i]-1);
	putchar('\n');
}
int Sa[6005],rk[3005],Rk[3005],ct[3005],m;
inline void Sort(){
	rep(i,0,m)ct[i]=0;
	repn(i)ct[rk[i]]++;
	repm(i)ct[i]+=ct[i-1];
	per(i,n,1)Sa[ct[rk[Rk[i]]]--]=Rk[i];
}
inline void Ssort(){
	repn(i)rk[i]=a[i],Rk[i]=i;
	m=3;
	Sort();
	for(int len=1;len<=n;len<<=1){
		int k=0;
		rep(i,n-len+1,n)Rk[++k]=i;
		repn(i)if(Sa[i]>len)Rk[++k]=Sa[i]-len;
		Sort(),swap(rk,Rk),rk[Sa[1]]=k=1;
		rep(i,2,n)rk[Sa[i]]=Rk[Sa[i]]==Rk[Sa[i-1]]&&Rk[Sa[i]+len]==Rk[Sa[i-1]+len]?k:++k;
		if(k==n)return;
		m=k;
	}
}
int pr[N];
inline int gets(int l,int r){
	if(l>r)return 0;
	return pr[r]-pr[l-1];
}
inline bool check(int gp){
	rep(i,1,gp)a[sa[i]]=1;
	rep(i,gp+1,n)a[sa[i]]=2;
	Ssort();
	repn(i)if(sa[i]!=Sa[i])return 0;
	repn(i)pr[i]=pr[i-1]+a[i];
	repn(i){
		int w=len[i*2-1]/2;
		int Sum=gets(i-w,i+w);
		Sum-=a[i];
		int K=w*2;
		if(Sum!=K&&Sum!=K*2)return 0;
		if(i-w-1>=1&&i+w+1<=n&&a[i-w-1]==a[i+w+1])return 0;
	}
	rep(i,1,n-1){
		int w=len[i*2]/2;
		if(i-w>=1&&i+w+1<=1&&a[i-w]!=a[i+w+1])return 0;
		if(w)continue;
		int Sum=gets(i-w+1,i+w),K=len[i*2];
		if(Sum!=K&&Sum!=K*2)return 0;
	}
	repn(i)putchar('a'+a[i]-1);
	putchar('\n');
	return 1;
}
inline void subC(){
	per(i,n,1)if(check(i))return;
	puts("-1");
}
int rd[N];
inline void bfs(){
    queue<int>q;
    repn(i)if(!rd[i])a[i]=1,q.push(i);
    while(!q.empty()){
        int x=q.front();q.pop();
        E(x){
            a[y]=max(a[y],a[x]+1);
            if(!--rd[y])q.push(y);
        }
    }
}
inline void Main(){
	n=read();  
	bool speA=1;
	repn(i)sa[i]=read()+1,speA&=sa[i]==n-i+1,f[i]=i;f[n+1]=n+1;
	rep(i,1,n*2-1)len[i]=read();
	repn(i){
		if(len[i*2-1]%2==0)return puts("-1"),void();
		if(i-len[i*2-1]/2<1||i+len[i*2-1]/2>n)return puts("-1"),void(); 
	}
	rep(i,1,n-1){
		if(len[i*2]&1)return puts("-1"),void();
		int w=len[i*2]/2;
		if(i-w+1<1||i+w>n)return puts("-1"),void();
	}
	repn(i)if(sa[i]>n)return puts("-1"),void();
	repn(i)c[i]=0;
	repn(i)c[sa[i]]++;
	repn(i)if(c[i]!=1)return puts("-1"),void();
	//manacher 提供了某些字符相等/不等
	//先把相等的性质给处理了
	if(n<=8)return subtask0(),void();
	if(speA)return subA(),void();
	if(n<=3000)return subC(),void();
	repn(i)p[i].clear(),rk[sa[i]]=i,a[i]=rd[i]=0,f[i]=i;
    rep(i,1,n-1){
        if(!len[i*2]){
            if(rk[i]<rk[i+1])p[i].pb(i+1);
            else p[i+1].pb(i);
        }else {
            int w=len[i*2]/2;
            if(i-w>=1&&i+w+1<=n){
                if(rk[i-w]<rk[i+w+1])p[i-w].pb(i+w+1);
                else p[i+w+1].pb(i-w);
            }
        }
    }
    repn(i){
        int w=len[i*2-1]/2;
        if(i-w-1>=1&&i+w+1<=n){
            if(rk[i-w-1]<rk[i+w+1])p[i-w-1].pb(i+w+1);
            else p[i+w+1].pb(i-w-1);
        }
    }
    repn(i)E(i)if(find(i)==find(y))return puts("-1"),void();
    repn(i)E(i)rd[y]++;
    bfs();
    repn(i)if(rd[i])return puts("-1"),void();
    rep(i,2,n)a[sa[i]]=max(a[sa[i]],a[sa[i-1]]);
    repn(i)if(a[i]>26)return puts("-1"),void();
    repn(i)putchar(a[i]+'a'-1);
    putchar('\n');
}
signed main(){
	freopen("string.in","r",stdin);
	freopen("string.out","w",stdout);
	int T=read();
	while(T--)Main();
	return 0;
}